package gamebackend;

import framework.Color;
import framework.GraphicsWrapper;
import framework.ImageWrapper;
import framework.ResourcesWrapper;

public class PowerUp {
	public enum Type {
		SPEED("boost.png"),
		REPAIR("repair.png"),
		DECOY("powerup_decoy.png");
		private final String my_path;
		private ImageWrapper my_image;
		private Type(String the_path) {
			my_path = the_path;
		}
		public void initialize(final ResourcesWrapper the_resources) {
			my_image = the_resources.loadImage(my_path);
		}
		public ImageWrapper getImage() {
			return my_image;
		}
	}
	private final ImageWrapper my_image;
	public static void initialize(final ResourcesWrapper the_resources) {
		for (Type t : Type.values()) {
			t.initialize(the_resources);
		}
	}
	public static final int WIDTH = 20;
	private final Type my_type;
	private double my_x;
	private double my_y;
	protected PowerUp(final Type the_type, final double the_x, final double the_y) {
		my_type = the_type;
		my_image = the_type.getImage();
		my_x = the_x;
		my_y = the_y;
	}
	public void step(final int timeDelta, final double cameraYChange) {
		my_y += cameraYChange;
	}
	public double getY() {
		return my_y;
	}
	public double getX() {
		return my_x;
	}
	public void render(GraphicsWrapper g) {
		if (my_image != null) {
			g.saveMatrix();
			g.translate(getX() - WIDTH / 2, getY() - WIDTH / 2);
			g.scale((double)WIDTH / my_image.getHeight(), (double)WIDTH / my_image.getHeight());
			g.drawImage(my_image, 0, 0);
			g.restoreMatrix();
		} else {
			g.setColor(Color.RED);
			g.fillOval((int) my_x - WIDTH / 2, (int) my_y - WIDTH / 2, WIDTH, WIDTH);
		}
	}
	public boolean collides(final double the_x, final double the_y) {
		final double a = my_x - the_x;
		final double b = my_y - the_y;
		return a * a + b * b < (WIDTH / 2 + 10) * (WIDTH / 2 + 10);
	}
	public Type getType() {
		return my_type;
	}

}
